package com.iteaj.iot.plc.melsec;

import com.github.xingshuangs.iot.common.buff.ByteWriteBuff;
import com.github.xingshuangs.iot.protocol.melsec.enums.EMcFrameType;
import com.github.xingshuangs.iot.protocol.melsec.model.McAccessRoute;

public class MelsecMessageHeader3E extends  MelsecMessageHeader{
    protected int dataLength = 0;
    public MelsecMessageHeader3E() {
    }
    public MelsecMessageHeader3E(McAccessRoute accessRoute, int timer) {
        this.frameType = EMcFrameType.FRAME_3E;
        this.subHeader = this.frameType.getReqSubHeader();
        this.accessRoute = accessRoute;
        this.monitoringTimer = timer / 250;
        int length = 2 + this.accessRoute.byteArrayLength() + 2 + 2;
        this.setMessage(ByteWriteBuff.newInstance(length, true)
                .putShort(this.subHeader)
                .putBytes(this.accessRoute.toByteArray())
                .putShort(this.dataLength)
                .putShort(this.monitoringTimer)
                .getData());
    }
}
